package com.acme.bankapp.domain.bank;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

public class Bank {
	private Set<Client> clients = new HashSet<>();
	private ClientRegisrationListener[] listeners = new ClientRegisrationListener[2];

	Bank() {

		class PrintClientListener implements ClientRegisrationListener {

			public void onClientAdded(Client c) {
				final SimpleDateFormat formatter = new SimpleDateFormat(
						"dd.MM.yyyy hh:mm");
				c.getClientSalutation();
				System.out.println(": " + "add at "
						+ formatter.format(new Date()));
			}
		}

		class EmailNotificationListener implements ClientRegisrationListener {

			public void onClientAdded(Client c) {
				System.out.print("Notification email for client ");
				c.getClientSalutation();
				System.out.println(" to be send");
			}
		}
		listeners[0] = new PrintClientListener();
		listeners[1] = new EmailNotificationListener();
	}

	Bank(ClientRegisrationListener... listeners) {
		this.listeners = listeners;
	}

	public Set<Client> getClients() {
		return clients;
	}

	public void setClient(Client client) {
		clients.add(client);
	}

	public ClientRegisrationListener[] getListeners() {
		return listeners;
	}
}
